

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>CephFS 支持的能力 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="CephFS API （编程接口）" href="../api/" />
    <link rel="prev" title="Journaler" href="../journaler/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../">Ceph 文件系统</a> &raquo;</li>
        
      <li>CephFS 支持的能力</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/cephfs/capabilities.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../">
          

          
            
            <img src="../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 文件系统</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../#cephfs">CephFS 入门</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id4">管理</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id5">挂载 CephFS</a></li>
<li class="toctree-l2"><a class="reference internal" href="../#id6">CephFS 内幕</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../#id7">故障排除和灾难恢复</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../eviction/"> 驱逐客户端</a></li>
<li class="toctree-l3"><a class="reference internal" href="../scrub/"> 洗刷</a></li>
<li class="toctree-l3"><a class="reference internal" href="../full/"> 文件系统占满的处理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../disaster-recovery-experts/"> 元数据修复</a></li>
<li class="toctree-l3"><a class="reference internal" href="../troubleshooting/"> 故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../disaster-recovery/"> 灾难恢复</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cephfs-journal-tool/"> cephfs-journal-tool</a></li>
<li class="toctree-l3"><a class="reference internal" href="../recover-fs-after-mon-store-loss/"> 监视器存储丢失后恢复文件系统</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="../#id8">开发者指南</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="../journaler/"> Journaler 配置</a></li>
<li class="toctree-l4 current"><a class="current reference internal" href="#"> 客户端的能力</a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/"> Java 和 Python 捆绑库</a></li>
<li class="toctree-l4"><a class="reference internal" href="../mantle/"> Mantle</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../#id9">更多细节</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="cephfs">
<h1>CephFS 支持的能力<a class="headerlink" href="#cephfs" title="Permalink to this headline">¶</a></h1>
<p>一个客户端想要操作索引节点时，它会向 MDS 发起多种查询， MDS 会授予此客户端一系列<em>能力（ capabilities ）</em>，有了这些能力，客户端就有权限操作索引节点了。与其它网络文件系统（如 NFS 或 SMB
）相比，一个主要的区别在于这些授予的能力非常粗糙，而且它允许多个客户端同时持有同一索引节点的不同能力。</p>
<div class="section" id="id1">
<h2>能力的种类<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<p>有几种“常规”能力位，以下是定义。</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cm">/* generic cap bits */</span><span class="w"></span>
<span class="cp">#define CEPH_CAP_GSHARED     1  </span><span class="cm">/* (metadata) client can reads (s) */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_GEXCL       2  </span><span class="cm">/* (metadata) client can read and update (x) */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_GCACHE      4  </span><span class="cm">/* (file) client can cache reads (c) */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_GRD         8  </span><span class="cm">/* (file) client can read (r) */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_GWR        16  </span><span class="cm">/* (file) client can write (w) */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_GBUFFER    32  </span><span class="cm">/* (file) client can buffer writes (b) */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_GWREXTEND  64  </span><span class="cm">/* (file) client can extend EOF (a) */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_GLAZYIO   128  </span><span class="cm">/* (file) client can perform lazy io (l) */</span><span class="cp"></span>
</pre></div>
</div>
<p>这些能力是通过二进制数字的位翻转定义的，用以表示与某一索引节点的数据或元数据相关的能力：</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cm">/* per-lock shift */</span><span class="w"></span>
<span class="cp">#define CEPH_CAP_SAUTH      2 </span><span class="cm">/* A */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_SLINK      4 </span><span class="cm">/* L */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_SXATTR     6 </span><span class="cm">/* X */</span><span class="cp"></span>
<span class="cp">#define CEPH_CAP_SFILE      8 </span><span class="cm">/* F */</span><span class="cp"></span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>译者注：下面这段没完全理解，也许翻译的有问题，先附上原文。</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">译文</dt>
<dd class="field-odd"><p>然而，以前只有某些常规能力授予了其中的一些“位移”，特别是，只有
FILE 位移多于前两位。</p>
</dd>
<dt class="field-even">原文</dt>
<dd class="field-even"><p>Only certain generic cap types are ever granted for some of those “shifts”,
however. In particular, only the FILE shift ever has more than the first two
bits.</p>
</dd>
</dl>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">|</span> <span class="n">AUTH</span> <span class="o">|</span> <span class="n">LINK</span> <span class="o">|</span> <span class="n">XATTR</span> <span class="o">|</span> <span class="n">FILE</span>
<span class="mi">2</span>      <span class="mi">4</span>      <span class="mi">6</span>       <span class="mi">8</span>
</pre></div>
</div>
<p>从以上定义我们得到一个常数，它是用各个位值移位到相应的位（用变量表示）生成的：</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cp">#define CEPH_CAP_AUTH_SHARED  (CEPH_CAP_GSHARED  &lt;&lt; CEPH_CAP_SAUTH)</span>
</pre></div>
</div>
<p>然后，这些位就可以通过或操作产生位掩码（ bitmask ），用以表示一系列能力。</p>
<p>有一个例外的：</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cp">#define CEPH_CAP_PIN  1  </span><span class="cm">/* no specific capabilities beyond the pin */</span><span class="cp"></span>
</pre></div>
</div>
<p>pin 只是把 inode 插入内存，不授予任何能力。</p>
<p>图形化就是：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">+---+---+---+---+---+---+---+---+</span>
<span class="o">|</span> <span class="n">p</span> <span class="o">|</span> <span class="n">_</span> <span class="o">|</span><span class="n">As</span>   <span class="n">x</span> <span class="o">|</span><span class="n">Ls</span>   <span class="n">x</span> <span class="o">|</span><span class="n">Xs</span>   <span class="n">x</span> <span class="o">|</span>
<span class="o">+---+---+---+---+---+---+---+---+</span>
<span class="o">|</span><span class="n">Fs</span>   <span class="n">x</span>   <span class="n">c</span>   <span class="n">r</span>   <span class="n">w</span>   <span class="n">b</span>   <span class="n">a</span>   <span class="n">l</span> <span class="o">|</span>
<span class="o">+---+---+---+---+---+---+---+---+</span>
</pre></div>
</div>
<p>当前尚未使用第二个 bit 。</p>
</div>
<div class="section" id="cap">
<h2>各个 cap 授予的能力<a class="headerlink" href="#cap" title="Permalink to this headline">¶</a></h2>
<p>这就解释完了能力是如何授予的（和通讯的），以下重要的位说明了允许客户端干什么：</p>
<ul class="simple">
<li><p>PIN: 只是把 inode 插入内存。这足以让客户端取得 inode 号，还有其它的不可变信息，如设备 inode 的主、次设备号、或符号链接内容。</p></li>
<li><p>AUTH: 授予能力以获取与认证相关的元数据，特别是所有者、组和权限位。需要注意的是，完整的权限检查也许还要获取 ACL ，它是存在扩展属性（ xattrs ）里的。</p></li>
<li><p>LINK: inode 的链接计数。</p></li>
<li><p>XATTR: 访问或修改扩展属性的能力。另外，由于 ACL 定义存在扩展属性里，有时候检查权限还需访问它们。</p></li>
<li><p>FILE: 这是个大头，允许客户端访问和修改数据。也涵盖了与文件数据相关的元数据——特别是尺寸、 mtime 、 atime 、 ctime 。</p></li>
</ul>
</div>
<div class="section" id="id2">
<h2>简写<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<p>需要注意的是，客户端日志里会紧凑地表达各个能力，例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pAsLsXsFs</span>
</pre></div>
</div>
<p>其中， p 表示 pin ，各大写字母对应位移值，而位移值后面的小写字母是真正赋予此位置的的能力。</p>
</div>
<div class="section" id="the-relation-between-the-lock-states-and-the-capabilities">
<h2>The relation between the lock states and the capabilities<a class="headerlink" href="#the-relation-between-the-lock-states-and-the-capabilities" title="Permalink to this headline">¶</a></h2>
<p>In MDS there are four different locks for each inode, they are simplelock,
scatterlock, filelock and locallock. Each lock has several different lock
states, and the MDS will issue capabilities to clients based on the lock
state.</p>
<p>In each state the MDS Locker will always try to issue all the capabilities to the
clients allowed, even some capabilities are not needed or wanted by the clients,
as pre-issuing capabilities could reduce latency in some cases.</p>
<p>If there is only one client, usually it will be the loner client for all the inodes.
While in multiple clients case, the MDS will try to caculate a loner client out for
each inode depending on the capabilities the clients (needed | wanted), but usually
it will fail. The loner client will always get all the capabilities.</p>
<p>The filelock will control files’ partial metadatas’ and the file contents’ access
permissions. The metadatas include <strong>mtime</strong>, <strong>atime</strong>, <strong>size</strong>, etc.</p>
<p><strong>Fs</strong>: Once a client has it, all other clients are denied <strong>Fw</strong>.</p>
<dl>
<dt><strong>Fx</strong>: Only the loner client is allowed this capability. Once the lock state transitions</dt><dd><p>to LOCK_EXCL, the loner client is granted this along with all other file capabilities
except the <strong>Fl</strong>.</p>
</dd>
<dt><strong>Fr</strong>: Once a client has it, the <strong>Fb</strong> capability will be already revoked from all</dt><dd><p>the other clients.</p>
<p>If clients only request to read the file, the lock state will be transferred
to LOCK_SYNC stable state directly. All the clients can be granted <strong>Fscrl</strong>
capabilities from the auth MDS and <strong>Fscr</strong> capabilities from the replica MDSes.</p>
<p>If multiple clients read from and write to the same file, then the lock state
will be transferred to LOCK_MIX stable state finally and all the clients could
have the <strong>Frwl</strong> capabilities from the auth MDS, and the <strong>Fr</strong> from the replica
MDSes. The <strong>Fcb</strong> capabilities won’t be granted to all the clients and the
clients will do sync read/write.</p>
</dd>
<dt><strong>Fw</strong>: If there is no loner client and once a client have this capability, the <strong>Fsxcb</strong></dt><dd><p>capabilities won’t be granted to other clients.</p>
<p>If multiple clients read from and write to the same file, then the lock state
will be transferred to LOCK_MIX stable state finally and all the clients could
have the <strong>Frwl</strong> capabilities from the auth MDS, and the <strong>Fr</strong> from the replica
MDSes. The <strong>Fcb</strong> capabilities won’t be granted to all the clients and the
clients will do sync read/write.</p>
</dd>
<dt><strong>Fc</strong>: This capability means the clients could cache file read and should be issued</dt><dd><p>together with <strong>Fr</strong> capability and only in this use case will it make sense.
While actually in some stable or interim transitional states they tend to keep
the <strong>Fc</strong> allowed even the <strong>Fr</strong> capability isn’t granted as this can avoid
forcing clients to drop full caches, for example on a simple file size extension
or truncating use case.</p>
</dd>
<dt><strong>Fb</strong>: This capability means the clients could buffer file write and should be issued</dt><dd><p>together with <strong>Fw</strong> capability and only in this use case will it make sense.
While actually in some stable or interim transitional states they tend to keep
the <strong>Fc</strong> allowed even the <strong>Fw</strong> capability isn’t granted as this can avoid
forcing clients to drop dirty buffers, for example on a simple file size extension
or truncating use case.</p>
</dd>
<dt><strong>Fl</strong>: This capability means the clients could perform lazy io. LazyIO relaxes POSIX</dt><dd><p>semantics. Buffered reads/writes are allowed even when a file is opened by multiple
applications on multiple clients. Applications are responsible for managing cache
coherency themselves.</p>
</dd>
</dl>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../api/" class="btn btn-neutral float-right" title="CephFS API （编程接口）" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../journaler/" class="btn btn-neutral float-left" title="Journaler" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>